package com.stadium.controller;

import java.util.List;
import java.util.UUID;

import com.stadium.common.BaseResponse;
import com.stadium.dto.BasicsRecordDto;
import com.stadium.service.BasicsRecordSV;
import com.stadium.vo.BasicsRecordVo;
import com.stadium.vo.ScheduleRecordVo;
import com.stadium.vo.searchVo.BasicsRecordSearchVo;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 比赛事件记录表
 *
 * @author wsl
 * @email
 * @date 2021-06-14 22:19:04
 */
@RestController
@RequestMapping("/api/basicsrecord")
@Api(tags = "比赛事件记录表")
public class BasicsRecordCL{
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private BasicsRecordSV basicsRecordSV;

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/v1/save")
    public BaseResponse save(@Validated @RequestBody ScheduleRecordVo scheduleRecordVo) {
        try {
            basicsRecordSV.save(scheduleRecordVo);
            //todo 数据统计
            return BaseResponse.ok();

        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error("网络错误，请检查网络稍后重试");
        }
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/v1/delete")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse delete(@RequestParam(name = "id", required = true)String id) {
        try {
            basicsRecordSV.delete(id);
            return BaseResponse.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "批量删除")
    @PostMapping(value = "/v1/deleteBatch")
    @ApiImplicitParams({@ApiImplicitParam(name="ids",value="ids")})
    public BaseResponse deleteBatch(@RequestParam(name = "ids", required = true)String[] ids) {
        try {
            basicsRecordSV.deleteBatch(ids);
            return BaseResponse.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "")
    @GetMapping(value = "/v1/query")
    public BaseResponse<List<BasicsRecordDto>> query(@Validated BasicsRecordSearchVo searchVo) {
        try {
            if (StringUtils.isNotEmpty(searchVo.getSearchValue())) {
                searchVo.setSearchValue("%" + searchVo.getSearchValue() + "%");
            }
            List<BasicsRecordDto> queryList = basicsRecordSV.query(searchVo);
            int total = basicsRecordSV.getCount(searchVo);
            return BaseResponse.ok(queryList, total);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "获得详情", notes = "获得详情")
    @GetMapping(value = "/v1/get")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse<BasicsRecordDto> get(@RequestParam(name = "id", required = true)String id) {
        try {
                BasicsRecordDto queryData = basicsRecordSV.get(id);
            return BaseResponse.ok(queryData);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }
}
